package com.zzxy.spring.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.sql.Ref;
@Component
@Aspect
public class MyAspectJ {
    @Pointcut("execution(* com.zzxy.spring.service.impl.*.*(..))")
    public void myPiontcut(){

    }
    @Before("myPiontcut()")
    public  void myBefore(JoinPoint jp) {
        System.out.println("before method "+jp.getSignature().getName());
        System.out.println("before ...");
    }
    @AfterReturning(value = "myPiontcut()",returning = "ret")
    public  void myAfterReturning(JoinPoint jp,Object ret){
        System.out.println("after returning .."+ ret);
    }
    @Around("myPiontcut()")
    public Object  myAround(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("around before ..");
        Object obj = pjp.proceed();
        System.out.println("around after ..");
        return obj;
    }
    @AfterThrowing(value = "myPiontcut()" ,throwing="e")
    public  void  myThrowable(JoinPoint jp,Throwable e){
        System.out.println("throwing .."+e.getMessage());
        //write to log
    }
    @After("myPiontcut()")
    public  void myAfter(JoinPoint jp){
        System.out.println(jp.getSignature().getName());
        System.out.println("after ...");
    }
}
